package cnsatmsmart.automation.mmi.model.layers;

/**
 * @author SIK - PTIK, BPPT
 **/

import com.bbn.openmap.omGraphics.OMGraphic;
import com.bbn.openmap.proj.Projection;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.io.Serializable;

public class OMLabelCircle extends OMGraphic implements Serializable {
    /* const */
        private static final Color FIXES_COLOR = new Color (225, 225, 225, 100);
            //nilai warna default untuk pewarnaan pada penggambaran lingkaran yang merupakan instance dari kelas OMLabelCircle
        private static final int FIXES_RADIUS = 16;
            //nilai jari-jari default pada penggambaran lingkaran yang merupakan instance dari kelas OMLabelCircle
    
    /* atribut - atribut yang dimiliki oleh kelas OMLabelCircle */
        private float latitude;             //posisi titik pusat object pada garis lintang
        private float longitude;            //posisi titik pusat object pada garis bujur
        private int xPoint = 0;             //posisi titik pusat object pada bidang kartesian searah sumbu axis
        private int yPoint = 0;             //posisi titik pusat object pada bidang kartesian searah sumbu ordinat
        private int radius = FIXES_RADIUS;  //jari-jari object
        private String label;               //label dari object
        private Color color = FIXES_COLOR;  //warna dari object
        private boolean fill = false;       //bernilai true jika dan hanya jika object solid dan sebaliknya false jika dan hanya jika penggambaran hanya berupa outline saja

    /* constructor - user defined ctor, no default ctor */
        // <editor-fold defaultstate="collapsed" desc="ctor">
        /*
         * @param = atribut
         */
        public OMLabelCircle (float lat, float lon) {
            this(lat, lon, FIXES_RADIUS, null, FIXES_COLOR, false);
        }
        public OMLabelCircle (float lat, float lon, int rad) {
            this(lat, lon, rad, null, FIXES_COLOR, false);
        }
        public OMLabelCircle (float lat, float lon, int rad, Color color, boolean fill) {
            this(lat, lon, rad, null, color, fill);
        }
        public OMLabelCircle (float lat, float lon, String label) {
            this(lat, lon, FIXES_RADIUS, label, FIXES_COLOR, false);
        }
        public OMLabelCircle (float lat, float lon, int rad, String label) {
            this(lat, lon, rad, label, FIXES_COLOR, false);
        }
        public OMLabelCircle (float lat, float lon, int rad, String label, Color color, boolean fill) {
            this.latitude = lat;
            this.longitude = lon;
            this.radius = rad;
            this.label = label;
            this.color = color;
            this.fill = fill;
        }
        // </editor-fold>

    @Override
    public boolean generate (Projection prjctn) {
        Point point = prjctn.forward(this.latitude, this.longitude);

        this.xPoint = point.x;
        this.yPoint = point.y;
    
        return (true);
    }

    @Override
    public void render (Graphics graphics) {
        Graphics2D g2d = (Graphics2D) graphics;
        g2d.setColor(this.color);

        if (isSelected()) {
            setGraphicsColor(graphics, Color.ORANGE);
        }

        if (this.fill) {
            g2d.fillOval((this.xPoint - (this.radius / 2)), (this.yPoint - (this.radius / 2)), this.radius, this.radius);
        } else {
            g2d.drawOval((this.xPoint - (this.radius / 2)), (this.yPoint - (this.radius / 2)), this.radius, this.radius);
        }

        if (this.label != null) {
            FontMetrics fm = g2d.getFontMetrics();
            int w = fm.stringWidth(this.label);
            int h = fm.getHeight();
            g2d.drawString(this.label, this.xPoint, this.yPoint);
        }
    }
}
